package com.ruoyi.wx.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wx.domain.WxVip;
import com.ruoyi.wx.service.IWxVipService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * vipController
 * 
 * @author wt
 * @date 2020-12-13
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wx/wxVip" )
public class WxVipController extends BaseController {

    private final IWxVipService iWxVipService;

    /**
     * 查询vip列表
     */
    @PreAuthorize("@ss.hasPermi('wx:wxVip:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxVip wxVip)
    {
        startPage();
        LambdaQueryWrapper<WxVip> lqw = Wrappers.lambdaQuery(wxVip);
        if (StringUtils.isNotBlank(wxVip.getNickname())){
            lqw.like(WxVip::getNickname ,wxVip.getNickname());
        }
        if (StringUtils.isNotBlank(wxVip.getWxid())){
            lqw.eq(WxVip::getWxid ,wxVip.getWxid());
        }
        if (StringUtils.isNotBlank(wxVip.getWxRemark())){
            lqw.eq(WxVip::getWxRemark ,wxVip.getWxRemark());
        }
        if (StringUtils.isNotBlank(wxVip.getWxName())){
            lqw.like(WxVip::getWxName ,wxVip.getWxName());
        }
        if (StringUtils.isNotBlank(wxVip.getWxh())){
            lqw.eq(WxVip::getWxh ,wxVip.getWxh());
        }
        if (StringUtils.isNotBlank(wxVip.getRobotWxid())){
            lqw.eq(WxVip::getRobotWxid ,wxVip.getRobotWxid());
        }
        if (wxVip.getType() != null){
            lqw.eq(WxVip::getType ,wxVip.getType());
        }
        if (wxVip.getState() != null){
            lqw.eq(WxVip::getState ,wxVip.getState());
        }
        if (StringUtils.isNotBlank(wxVip.getNote())){
            lqw.eq(WxVip::getNote ,wxVip.getNote());
        }
        if (wxVip.getAmount() != null){
            lqw.eq(WxVip::getAmount ,wxVip.getAmount());
        }
        List<WxVip> list = iWxVipService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出vip列表
     */
    @PreAuthorize("@ss.hasPermi('wx:wxVip:export')" )
    @Log(title = "vip" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(WxVip wxVip) {
        LambdaQueryWrapper<WxVip> lqw = new LambdaQueryWrapper<WxVip>(wxVip);
        List<WxVip> list = iWxVipService.list(lqw);
        ExcelUtil<WxVip> util = new ExcelUtil<WxVip>(WxVip. class);
        return util.exportExcel(list, "wxVip" );
    }

    /**
     * 获取vip详细信息
     */
    @PreAuthorize("@ss.hasPermi('wx:wxVip:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iWxVipService.getById(id));
    }

    /**
     * 新增vip
     */
    @PreAuthorize("@ss.hasPermi('wx:wxVip:add')" )
    @Log(title = "vip" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxVip wxVip) {
        return toAjax(iWxVipService.save(wxVip) ? 1 : 0);
    }

    /**
     * 修改vip
     */
    @PreAuthorize("@ss.hasPermi('wx:wxVip:edit')" )
    @Log(title = "vip" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxVip wxVip) {
        return toAjax(iWxVipService.updateById(wxVip) ? 1 : 0);
    }

    /**
     * 删除vip
     */
    @PreAuthorize("@ss.hasPermi('wx:wxVip:remove')" )
    @Log(title = "vip" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iWxVipService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
